package com.revenant.driver.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.cardview.widget.CardView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.revenant.driver.R;
import com.revenant.driver.base.BaseActivity;
import com.revenant.driver.bean.OilBean;
import com.revenant.driver.bean.ShipperBean.FaPiaoTaiTouDetailBen;
import com.revenant.driver.utils.Constants;
import com.revenant.driver.utils.GsonUtil;
import com.revenant.driver.utils.SPUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DriverOilApplyActivity extends BaseActivity {
    @BindView(R.id.car_num)
    TextView carNum;
    @BindView(R.id.click)
    CardView click;
    private Context context;

    @Override
    public int getContentViewResId() {
        context = this;
        return R.layout.activity_oil_apply;
    }

    @Override
    public void initView() {
        setcenterTitle("申请");
    }

    @Override
    public void initData() {
    }

    @Override
    public void leftbarclick() {
        super.leftbarclick();
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.click})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.click:
                getUrl();
                click.setClickable(false);
                break;
        }
    }

    private void getUrl() {
        Map<String, String> map = new HashMap<>();
        map.put("truckerMobile", SPUtils.getUsermobile(context));
        JSONObject jsonObject = new JSONObject(map);
        getH5Url(jsonObject);
    }

    private void getH5Url(JSONObject json) {
        OkGo.<String>post(Constants.Find_Oil_Apply_For)
                .upJson(json)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        OilBean detailBen = GsonUtil.parseJsonWithGson(response.body(), OilBean.class);
                        if (detailBen.getCode().equals("0")) {
                            showToast(detailBen.getMsg());
                            dismissDig();
                            finish();
                        } else {
                            dismissDig();
                        }


                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        dismissDig();
                    }
                });
    }

}
